package com.amit.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LoginAction  extends Action{
	
	@Override
	public ActionForward execute(ActionMapping am, ActionForm af,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		LoginForm lf=(LoginForm) af;
		String un=lf.getUsername();
		String pwd=lf.getPassword();
		String result=" ";
		if(un.equals(pwd))
		{
			result="success";
			request.setAttribute("UN", un);
			
		}
		else
		{
		 result="failed";
		 request.setAttribute("EMSG", "Invalid username or password");
		 
		}
		
		ActionForward forward=am.findForward(result);
		
		return forward;
	}
	

}
